package com.karst.essentials.chapter04
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;

	internal class MovieMaterialExample extends BasicView
	{
		public function MovieMaterialExample()
		{
			super() ;
			createView() ;
			startRendering() ;
		}

		private var plane : Plane = null ;
		private var sprite : Sprite = null ;
		private var txtField : TextField = null ;
		private var material : MovieMaterial = null ;
		private function createView() :  void
		{
			if( sprite == null )
			{
				sprite = new Sprite() ;
				sprite.graphics.beginFill( 0x333333 ) ;
				sprite.graphics.drawRect( 0, 0, 400, 400 ) ;
				sprite.graphics.endFill() ;
			}
			
			if( txtField == null )
			{
				txtField = new TextField() ;
				txtField.text = "Hello 3D world!" ;
				txtField.autoSize = TextFieldAutoSize.CENTER ;
				txtField.setTextFormat( new TextFormat( "Arial", 25, 0xFFFFFF, true ) ) ;
				txtField.width = 400 ;
				txtField.y = 100 ;
				if( sprite )
					sprite.addChild( txtField ) ;
			}
			if( material == null )
			{
				material = new MovieMaterial( sprite ) ;
				material.smooth = true ;
				material.doubleSided = true ;
			}
			
			if( plane == null )
				plane = new Plane( material, 800, 800, 12, 10 ) ;
			
			scene.addChild( plane ) ;
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			super.onRenderTick( event ) ;
			if( plane )
				plane.localRotationY-- ;
		}
	}
}